package edu.utd.text.game.designer.commands;

import java.util.Scanner;

import edu.utd.text.game.designer.controller.DesignerController;
import edu.utd.text.game.domain.areas.Room;
import edu.utd.text.game.domain.exceptions.DuplicateRoomException;

public class CreateRoomCommand implements DesignerCommand {
	
	public CreateRoomCommand() {
		
	}
	
	//TODO: This implementation begs to be replaced with appropriate design pattern.
	//TODO: It doesn't really throw an exception but is required to have this signature 
	//because of the superclass signature...is there some way to avoid this?
	public String execute() throws Exception {
		Scanner scanner = new Scanner(System.in);
		System.out.println("Room name: ");
		String roomName = scanner.nextLine().trim();
		if (roomName.equals("") || roomName.isEmpty()) {
			return "Must enter a room name.";
		}
		Room room = new Room(roomName);
		try { 
			DesignerController.INSTANCE.addRoom(room); } 
		catch (DuplicateRoomException drx) {  
			return "A room with that name already already exists in the game map."; 
		}
		System.out.println("Description: ");
		String description = scanner.nextLine();
		room.setDescription(description);
		return "Done creating room: " + roomName;
	}
 
}
